package jspWebPj;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.util.Calendar;
import java.util.Date;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class temp {

	public static void main(String[] args) {
		
	}
	
	public static void writeExcel(){
		XSSFWorkbook wb = null;
		File exfile = new File("");
		try{
			wb = new XSSFWorkbook();//workbook생성 필요
			XSSFSheet st = wb.createSheet();//sheet생성
			
		}catch(Exception e){e.printStackTrace();}
	}
	
	public static void exZipfile(){
		ZipInputStream zi = null;
		try{
			String dir = "C:/Users/boomroom/Desktop/exZip";
			File zipfile = new File("C:/Users/boomroom/Desktop","testZip.zip");//압축 풀 대상 파일 지정
			zi = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipfile)));
			ZipEntry entry = null;
			while((entry = zi.getNextEntry()) != null){
				File targetFile = new File(dir, entry.getName());

				if(entry.isDirectory()) {// Directory 인 경우
					//targetFile.mkdir(); // 디렉토리 생성
					targetFile.mkdir();
				}else{ // File 인 경우
					FileOutputStream fos = null;
					try {
						File inDir = new File(targetFile.getParent());//압축파일 안의 구조 확인
						if(!inDir.exists()){//상위 디렉토리가 존재하지 않을 경우 생성
							inDir.mkdirs();
						}
					
						fos = new FileOutputStream(targetFile);

						byte[] buffer = new byte[1024];
						int len = 0;
						while ((len = zi.read(buffer)) != -1) {
							fos.write(buffer, 0, len);
						}
					}finally {
						if (fos != null) {
							fos.close();
						}
					}
				}
			}
			zi.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	public static void makeZipFile(){
		ZipOutputStream zo = null;
		try{
			File dirList = new File("C:/Users/boomroom/Desktop/zipList");//압축대상의 디렉토리
			File zipfile = new File("C:/Users/boomroom/Desktop","testZip.zip");//출력할 파일 지정
			zo = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipfile)));
			zo.setLevel(8); // 압축 레벨 - 최대 압축률은 9, 디폴트 8

			for (File file : dirList.listFiles()) {
				BufferedInputStream bis = null;
				try {
					bis = new BufferedInputStream(new FileInputStream(file));
					ZipEntry zentry = new ZipEntry(file.getName());
					zentry.setTime(file.lastModified());//파일의 수정 시간 기록(설정하지 않을 경우 압출할 때의 시간이 기록됨)
					zo.putNextEntry(zentry);//파일별 개별 요소로 입력

					byte[] buffer = new byte[1024];
					int cnt = 0;
					while ((cnt = bis.read(buffer, 0, 1024)) != -1) {
						zo.write(buffer, 0, cnt);//압축 파일작성
					}
					zo.closeEntry();
				}finally {
					if(bis != null) {
						bis.close();
					}
				}
			}
			zo.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	

	
	public void file(){
		Calendar cal = Calendar.getInstance();
		cal.add(Calendar.DATE, 1);
		System.out.println(cal.getMinimum(Calendar.MONTH));
		System.out.println(cal.getMaximum(Calendar.MONTH));
		Date date = new Date();
		
		File file = new File("C:/Users/boomroom/Desktop","filewrite.txt");
		FileWriter w = null;
		try{
			w = new FileWriter(file);
			w.write("test용 파일 작성1");
			w.write("\r\n");
			w.write("Filewriter");
			w.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		File file2 = new File("C:/Users/boomroom/Desktop","BufferedWriter.txt");
		BufferedWriter bw = null;
		try{
			bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2), "UTF-8"));
			String line = null;
			bw.write("test용 파일작성2");
			bw.newLine();
			bw.write("BufferedWriter");
			bw.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
